<template>
	<view class="">
		<!--  -->
		<ben></ben>
		<!--  -->
		<view class="min30 pad30 background_f rad2 row">
			<view class="flex1 column text_center font600 size36"
				style="border-right: 2rpx solid #EDEDED;color: #FE3C3C;">
				{{ userinfo.salesman_money }}
				<view class="row align_item_c col3 size28 font500 just_cont_c mintop20">
					<image src="@/static/image/42.png" class="minright10" style="width: 36rpx;height: 34rpx;"></image>
					账户积分
				</view>
				<view class="col6 size24 font500 disflex align_item_b just_cont_c mintop10"
					@click="$jump.nav('/indexpackage/store/cashout')">
					积分提现
					<u-icon name="arrow-right" color="#666666" size="12"></u-icon>
				</view>
			</view>
			<view class="flex1 column text_center font600 size36" style="color: #FE3C3C;">
				{{ total_forehead }}
				<view class="row align_item_c col3 size28 font500 just_cont_c mintop20">
					<image src="@/static/image/120.png" class="minright10" style="width: 34rpx;height: 34rpx;"></image>
					团队总额
				</view>
				<view class="col6 size24 font500 disflex align_item_b just_cont_c mintop10"
					@click="$jump.nav('/mypackage/user/rebate')">
					团队返点
					<u-icon name="arrow-right" color="#666666" size="12"></u-icon>
				</view>
			</view>
		</view>
		<!-- <view class="">
			<uni-segmented-control :current="current" :values="items" @clickItem="onClickItem" styleType="text"
				activeColor="#FE9110"></uni-segmented-control>
		</view> -->

		<view class="" v-if="current == 0">
			<view class="empty" style="margin-top: 300rpx;" v-if="list.length == 0">
				<u-empty mode="data" icon="https://cdn.uviewui.com/uview/empty/data.png">
				</u-empty>
			</view>
			<view class="min30_rl mintop30 box pad20_rl padbottom20 row" v-for="(item,index) in list" :key="index"
				v-else>
				<u-avatar :src="item.avatar" size="50"></u-avatar>
				<view class="flex1 row minleft40 just_cont_spacebet">
					<view class="column font500 col6 size26	">
						<view class="row">
							用户：
							<view class="col0">
								{{ item.phone }}
							</view>
						</view>
						<view class="row minto minbottom0">
							累计金额：
							<view class="col0">
								{{ item.total_spent }}
							</view>
						</view>
					</view>
					<view class="column font500 col6 size26	">
						<view class="row">
							下单次数：
							<view class="col0">
								{{ item.total_orders }}
							</view>
						</view>
						<view class="row minto minbottom0" style="color: #FE3C3C;">
							获得积分：
							<view>
								{{ item.total_points }}
							</view>
						</view>
					</view>
				</view>
			</view>

			<!-- <view style="padding: 40rpx 0;"><u-loadmore :status="status" /></view> -->
		</view>
		<view class="" v-if="current == 1">
			<view class="empty" style="margin-top: 300rpx;" v-if="slist.length == 0">
				<u-empty mode="data" icon="https://cdn.uviewui.com/uview/empty/data.png">
				</u-empty>
			</view>
			<view v-else>
				<view class="min30_rl mintop30 box pad20_rl padbottom20 row" v-for="(item,index) in slist" :key="index">
					<u-avatar :src="item.avatar" size="50"></u-avatar>
					<view class="flex1 row minleft40 just_cont_spacebet">
						<view class="column font500 col6 size26	">
							<view class="row">
								用户：
								<view class="col0">
									{{ item.phone }}
								</view>
							</view>
							<view class="row minto minbottom0">
								累计金额：
								<view class="col0">
									{{ item.total_spent }}
								</view>
							</view>
						</view>
						<view class="column font500 col6 size26	">
							<view class="row">
								下单次数：
								<view class="col0">
									{{ item.total_orders }}
								</view>
							</view>
							<view class="row minto minbottom0" style="color: #FE3C3C;">
								获得积分：
								<view>
									{{ item.total_points }}
								</view>
							</view>
						</view>
					</view>
				</view>
				<!-- <view style="padding: 40rpx 0;"><u-loadmore :status="status" /></view> -->
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				userinfo: {},
				user_id: '',
				total_forehead: '',
				items: ['直推用户', '间推用户'],
				current: 0,
				page: 1,
				status: 'nomore',
				loadmore: [],
				list: [],
				slist: [],
			}
		},

		onLoad() {
			this.user_id = uni.getStorageSync('user_id');
			uni.pageScrollTo({
				scrollTop: 0,
				duration: 10 // 滚动动画时长，默认300ms
			});
			this.page = 1
			this.getUserinfo()
			this.getTeam()
			this.getTeamTotal()
		},
		// onReachBottom() {
		// 	if (this.page < 0) return;
		// 	this.status = 'loading';
		// 	this.page = ++this.page
		// 	this.getTeam()
		// 	setTimeout(() => {
		// 		console.log(this.loadmore);
		// 		if (this.loadmore.length == 0) this.status = 'nomore';
		// 		else this.status = 'loading';
		// 	}, 1000)
		// },
		methods: {
			async getUserinfo() {
				let {
					code,
					message,
					data
				} = await this.$com.fetchGet("member/user_info/" + this.user_id)
				if (code == 200) {
					this.userinfo = data

				} else {
					console.log(message);
				}
			},
			async getTeamTotal() {
				let {
					code,
					message,
					data
				} = await this.$com.fetchGet("member/total_forehead/" + this.user_id)
				if (code == 200) {
					this.total_forehead = data

				} else {
					console.log(message);
				}
			},
			async getTeam() {
				uni.showLoading({
					title: '加载中',
					mask: true
				})
				let {
					code,
					message,
					data
				} = await this.$com.fetchGet("member/team/" + this.user_id, {
					page: this.page,
					type: this.current == 0 ? 1 : 2
				})
				if (code == 200) {
					uni.hideLoading()
					this.loadmore = data
					this.list = data
				} else if (code == 500) {
					this.list = data
					this.loadmore = data
				} else {
					console.log(message);
				}
			},
			onClickItem(e) {
				if (this.current != e.currentIndex) {
					this.current = e.currentIndex;
				}
				this.page = 1
				this.list = []
				this.slist = []
				this.loadmore = []
				this.getTeam()
			},
		}
	}
</script>

<style scoped lang="less">
	.box {
		border-bottom: 2rpx solid #EDEDED;
	}
</style>